package classcode;

import sun.reflect.generics.tree.ReturnType;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author ZhengDp
 * @Date 2023/5/14 17:38
 * @Description 通过反射获取泛型信息
 */
public class ClassCode_Demo6 {

    public static void main(String[] args) throws Exception{
        Method method = ClassCode_Demo6.class.getMethod("test",List.class,Map.class);
        Type type = method.getGenericReturnType();
        if(type instanceof ParameterizedType) {
            ParameterizedType returnType = (ParameterizedType) type;
            System.out.println("原始类型 ： " + returnType.getRawType() );
            Type[] arguments = returnType.getActualTypeArguments();
            for(Type t : arguments) {
                System.out.println("泛型参数 ： " + t);
            }
        }
    }

    public Set<String> test(List<String> list, Map<String,Integer> map) {
        return null;
    }
}
